package priv.yiyuan.example.design.flyweight;

import java.awt.*;
import java.util.ArrayList;
import java.util.List;


public class Document {

    private List<Character> characters = new ArrayList<>();

    public void addCharacter(char value, String fontName, int fontSize, Color color, boolean bold, boolean italic) {
        CharacterFormat format = CharacterFormatFactory.getCharacterFormat(fontName, fontSize, color, bold, italic);
        Character character = new Character(value, format);
        characters.add(character);
    }

    public void renderDocument() {
        System.out.println("\n--- 渲染文档 ---");
        int x = 0, y = 0;
        for (Character character : characters) {
            character.render(x, y);
            x += 10;
        }

        System.out.println("\n--- 文档渲染完成 ---");
        System.out.println("缓存中享元对象数量: " + CharacterFormatFactory.getCacheSize());

    }

    public int getTotalCharacters() {
        return characters.size();
    }
}
